package com.yzt.minemodule.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.alibaba.android.arouter.facade.annotation.Route;
import com.yzt.zhuju.arouter.RouterMine;
import com.yzt.zhuju.base.BaseActivity;
import com.yzt.zhuju.network.AresSubscriber;
import com.yzt.zhuju.network.biz.BizLayer;
import com.yzt.zhuju.network.entity.mine.WatchVideoBean;
import com.yzt.zhuju.widget.tuiview.TUIImageView;
import com.yzt.zhuju.widget.tuiview.TUITextView;
import com.yzt.minemodule.R;

/**
 * author : bob
 * date   : 2023/2/22
 * desc   : 激励视频模块
 */
@SuppressLint("SetTextI18n")
@Route(path = RouterMine.ACTIVITY_WATCH_VIDEO)
public class WatchVideoActivity extends BaseActivity {

    private ProgressBar progressBar;

    private TUIImageView imgGet;

    private TUITextView tvGet;

    private TextView tvTime;

    private TextView tvTextTime;

    private RelativeLayout rlContainer;

    private static final String TAG = "WatchVideoActivity";

    private static final String AD_UNIT_ID = "ca-app-pub-3808811162495581/5256992659";


    private boolean isLoading;

    public static void start(Activity activity) {
        activity.startActivity(new Intent(activity, WatchVideoActivity.class));
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_watch_video;
    }

    @Override
    public void installViews() {
        setFullScreen(true);
        progressBar = findViewById(R.id.progress);
        tvTime = findViewById(R.id.tv_time);
        tvTextTime = findViewById(R.id.tv_text_time);
        imgGet = findViewById(R.id.img_get);
        tvGet = findViewById(R.id.tv_get);

        rlContainer = findViewById(R.id.rl_container);
        rlContainer.setOnClickListener(this);
        findViewById(R.id.img_back).setOnClickListener(this);
        rlContainer.setEnabled(false);
        getWatchVideoInfo();

    }

    /**
     * 获取观看视频的基础信息
     */
    private void getWatchVideoInfo() {
        // 用户信息
        BizLayer.getInstance().getAccountModule().getWatchVideoInfo(new AresSubscriber<WatchVideoBean>() {
            @Override
            protected void onSuccess(WatchVideoBean baseBean) {
                tvTime.setText(baseBean.getUseTimesToday() + " / " + baseBean.getTotalDailyFrequency());
                progressBar.setProgress((baseBean.getUseTimesToday() * 100) / baseBean.getTotalDailyFrequency());
                tvTextTime.setText(baseBean.getDiamondsDesc());
                imgGet.setSelected(baseBean.getUseTimesToday() == baseBean.getTotalDailyFrequency());
                tvGet.setSelected(baseBean.getUseTimesToday() == baseBean.getTotalDailyFrequency());
                if (baseBean.getUseTimesToday() == baseBean.getTotalDailyFrequency()) {
                    tvGet.setText(getString(R.string.watch_count_out, "" + baseBean.getUseTimesToday()));
                    rlContainer.setEnabled(false);
                    imgGet.setSelected(true);
                    tvGet.setSelected(true);
                } else {
                    tvGet.setText(getString(R.string.watch_now));
                    rlContainer.setEnabled(true);
                }
            }
        });
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        if (view.getId() == R.id.rl_container) {
        }

        if (view.getId() == R.id.img_back) {
            finish();
        }
    }
}
